import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import '../../public/repeat_fun.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import '../../public/itemList.dart';

class Journalism extends StatefulWidget {
  Journalism({Key key}) : super(key: key);

  @override
  _JournalismState createState() => _JournalismState();
}

class _JournalismState extends State<Journalism> {
  EasyRefreshController _controller;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = EasyRefreshController();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        centerTitle: true,
        leading: moveBack(context),
        title: Text('学校新闻'),
      ),
      body: EasyRefresh(
        enableControlFinishRefresh: false,
        enableControlFinishLoad: true,
        controller: _controller,
        header: ClassicalHeader(),
        footer: ClassicalFooter(),
        child: ListView.builder(
          itemBuilder: (context, index) {
            return Column(
              children: [
                MySwiper(),
                SizedBox(height: 50.h),
                Notice(),
              ],
            );
          },
          itemCount: 1,
        ),
        onRefresh: () async {},
        onLoad: () async {
          // _controller.finishLoad(success: true, noMore: false);
        },
      ),
    );
  }
}

class MySwiper extends StatefulWidget {
  MySwiper({Key key}) : super(key: key);

  @override
  _MySwiperState createState() => _MySwiperState();
}

class _MySwiperState extends State<MySwiper> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(25.w, 0, 25.w, 0),
      height: 305.h,
      child: new Swiper(
        itemBuilder: (BuildContext context, int index) {
          return ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: Image.network(
              "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1603365312,3218205429&fm=26&gp=0.jpg",
              fit: BoxFit.fill,
            ),
          );
        },
        loop: true,
        autoplay: true,
        // 显示的控制器
        pagination: SwiperPagination(
          builder: DotSwiperPaginationBuilder(
            activeColor: Colors.blue,
            color: Colors.grey,
            size: 8.0,
            activeSize: 10.0,
          ),
          margin: new EdgeInsets.all(5.0),
        ),
        itemCount: 3,
        viewportFraction: 0.8,
        scale: 0.9,
      ),
    );
  }
}

class Notice extends StatefulWidget {
  Notice({Key key}) : super(key: key);

  @override
  _NoticeState createState() => _NoticeState();
}

class _NoticeState extends State<Notice> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(25.w, 0, 25.w, 0),
      child: ListView.builder(
        // ignore: missing_return
        itemBuilder: (BuildContext context, int index) {
          return ItemOption();
        },
        physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        itemCount: 20,
      ),
    );
  }
}
